// pages/duBanBanli/duBanBanli.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  reportlist:[],//工作汇报列表
  },
  //新增汇报
	addReport:function(e){
		wx.navigateTo({
      url: '../addHuibao/addHuibao?id=' + this.data.id + '&huibaoId=' + id,
		})
	},
  //附件
  fuJian:function(){
    wx.navigateTo({
      url: '../fuJian/fuJian?id=' + this.data.id,
    })
  },

//   删除工作汇报
	delReport:function(e){
		var that = this;
		var index = e.currentTarget.dataset.index;
		var reportlist = this.data.reportlist;//汇报列表
   var id = reportlist[index].id;
		wx.showModal({
			content: '确定要删除工作汇报？',
			showCancel: true,
			success: function(res) {
        wx.request({
          url: app.globalData.url + '/schedule/del',
          header: app.header(),
          header: { "Content-Type": "application/x-www-form-urlencoded" },
          method: "POST",
          data: { id: id},
          success: function (res) {
            if (res.statusCode == 405) {
              app.getLogout();
              return;
            }
            if (res.data.success=='false') {
              wx.showToast({
                title: res.data.data.content,
                icon: 'loading',
                duration: 1500
              })
            } else {
              wx.showToast({
                title: '保存成功',//这里打印出登录成功
                icon: 'success',
                duration: 1000,
                success: function () {
                  console.log('haha');
                  setTimeout(function () {
                    reportlist.splice(index, 1);
                    that.setData({
                      reportlist: reportlist
                    })
                  }, 2000) //延迟时间
                }
              })
            }
          }
        });
			},
			fail: function(res) {},
			complete: function(res) {},
		})
	},

  //   编辑工作汇报
  editReport: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var reportlist = this.data.reportlist;//汇报列表
    var id = reportlist[index].id;
    wx.showModal({
      content: '确定要编辑工作汇报？',
      showCancel: true,
      success: function (res) {
        wx.navigateTo({
          url: '../addHuibao/addHuibao?id=' + that.data.id + '&huibaoId=' + id,
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  var _this=this;
  // var id =options.id;
  var id=36;
    wx.request({
      url: app.globalData.url + '/supervise/letterEvaluateDetail/'+id,
      header: app.header(),
      method: "GET",
      success: function (res) {
        if (res.statusCode == 405) {
          app.getLogout();
          return;
        }
        console.log(res.data.result);
        if (res.data.status == 'success') {
          _this.setData({
            id: res.data.result.id,
            title: res.data.result.title,
            letterNum: res.data.result.letterNum,
            completeTime: res.data.result.completeTime,
            typeName: res.data.result.typeName,
            urgencyDegreeName: res.data.result.urgencyDegreeName,
            reportlist: res.data.result.supervisionScheduleVOS,
          })
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})